<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></title>
		<script type="text/javascript">
			window.onload = function(){
				//抓id属性
				document.getElementById("btn1").onclick = function(){
					alert('id');
				}
				
				//抓class属性 会以数组形式返回
				document.getElementsByClassName('btn2')[0].onclick = function(){
					alert('class');
				}
				
				//抓name属性 会以数组形式返回
				document.getElementsByName('btn3')[0].onclick = function(){
					alert('name');
				}
				
				//抓标签名 会以数组形式返回
				document.getElementsByTagName('p')[0].onclick = function(){
					alert('tag');
				}
			}
			
		</script>
	</head>
	<body>	
		<button id="btn1">我有id属性</button><br />
		<button class="btn2">我有class属性</button><br />
		<button name="btn3">我有name属性</button><br />
		<p>4</p><br />
	</body>
</html>
